package com.cenntro.auth.utils;

import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import com.cenntro.auth.model.dbo.SysSooidDO;
import com.cenntro.common.model.dbo.BaseDO;

public class BeanFill {

	public static void fillByCreate(BaseDO base){
		if (StringUtils.isBlank(base.getCreateUser())){
			Subject subject = SecurityUtils.getSubject();
			if(subject != null  && subject.getSession() != null){
			    SysSooidDO user = (SysSooidDO)subject.getPrincipal();
				if (user != null){
					base.setCreateUser(user.getId().toString());
				}
			}
		}
		base.setCdt(new Date());
	}
	public static void fillByUpdate(BaseDO base){
		if (StringUtils.isBlank(base.getCreateUser())){
			Subject subject = SecurityUtils.getSubject();
			if(subject != null  && subject.getSession() != null){
			    SysSooidDO user = (SysSooidDO)subject.getPrincipal();
				//Object obj = subject.getSession().getAttribute("userName");
				if (user != null){
					base.setUpdateUser(user.getId().toString());
				}
			}
		}
		base.setUdt(new Date());
	}
}
